const form = document.getElementById('userForm');
form.addEventListener('submit', function (event) {
  event.preventDefault();

  const formData = new FormData(form);
  const resumeData = {};
  formData.forEach(function (value, key) {
    resumeData[key] = value;
  });
  console.log(resumeData)
  const usersId = localStorage.getItem('userId');
  if (!usersId) {
    alert('未获取到用户 ID，请重新登录');
    return;
  }
  const content = JSON.stringify(resumeData);

  fetch('http://192.168.244.14:8080/resumeStatus/add', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ usersId: parseInt(usersId), content })
  })
    .then(response => {
      if (!response.ok) {
        throw new Error('网络响应错误：' + response.status);
      }
      return response.json();
    })
    .then(data => {
      console.log('后端返回的数据:', data);
      if (data && data.code === 1) {
        alert('简历提交成功');
        localStorage.setItem('resumeData', JSON.stringify(resumeData));
      } else {
        alert('简历提交失败：' + (data && data.msg ? data.msg : '未知错误'));
      }
    })
    .catch(error => {
      console.error('提交简历请求出错:', error);
      alert('提交简历请求出错，请检查网络连接');
    });
});
function fetchResumeData(userId) {
  fetch(`http://192.168.244.14:8080/resumeStatus/view/${userId}`)
    .then(response => {
      if (!response.ok) {
        throw new Error('网络响应错误：' + response.status);
      }
      return response.json();
    })
    .then(data => {
      if (data && data.code === 1) {
        localStorage.setItem('resumeData', JSON.stringify(data.data));
      } else {
        alert('获取简历失败：' + (data && data.msg ? data.msg : '未知错误'));
      }
    })
    .catch(error => {
      console.error('获取简历请求出错:', error);
      alert('获取简历请求出错，请检查网络连接');
    });
}